
***** globals *****
set more off
global projectdir "~"
global datadir "$projectdir/data"
global results "$projectdir/results"


 

****************************************
*******Event Study************
****************************************
*Figure 4: The Effects of Federal Funding Shocks on High-tech Enterprenerurship

u "$datadir/jobhist_lehd_E_06102021.dta", clear

est clear
set more off

tab tau, gen(shock_dummies)

eststo: reghdfe ht_overage shock_dummies1-shock_dummies13 shock_dummies15-shock_dummies28   , a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster emp_num) keepsingletons 

esttab using "$results/event_study_07122021.csv", label nogaps r2 ar2 star(* 0.1 ** 0.05 *** 0.01) b(%9.4g) se(%9.4g) scalars(widstat N_clust) sfmt(%9.0g) replace



****************************************
*******OLS REGRESSIONS USING SHOCKS************
****************************************
u "$datadir/jobhist_lehd_E_06102021.dta", clear 

//Note: Reghfe does not report observations in cells dropped because they are saturated by FE
//use keepsingletons to keep for not creating implicit samples

est clear
set more off

*Table 2: The Effects of Federal Funding Cuts on High-tech Enterprenerurship
eststo: reghdfe count_ht_mode_start_2012 post if in_sample==1, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster emp_num) keepsingletons 


*Table 3: The Effects of Federal Funding Cuts on High-tech Enterprenerurship by Occupation
foreach occup of varlist occup_faculty occup_gradpostdoc occup_undergradstudent occup_other_staff {
sum `occup'
eststo: reghdfe count_ht_mode_start_2012 post if `occup'==1 & in_sample==1, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster emp_num) keepsingletons 
}

*Table 6: The Effects of Federal Funding Cuts on High-tech Enterprenerurship by Ex-ante Research Grant Timing
merge m:1 year iris_employee_number using  "$alex_transfer/grant_expiration.dta"
drop if _m == 2
drop _m

replace post_expire = post if missing(post_expire)
replace post_expire = 0 if post==0
replace post_new = 0 if missing(post_new)
replace post_new = 0 if post==0

eststo: reghdfe count_ht_mode_start_2012 post_new post_expire, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster emp_num) keepsingletons

test post_new = post_expire




*Table A.2 The Effects of Federal Funding Cuts on Addtional Career Outcomes
foreach var of varlist count_start young count_ht_mode_young_2012 alt_univ_ein_max R1 log_wage {
sum `var'
eststo: reghdfe `var' post  if in_sample==1, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster emp_num) keepsingletons 
}


* Cluster errors by dept-univ (Table A5)
eststo: reghdfe count_ht_mode_start_2012 post  if in_sample==1, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster field_univ) keepsingletons 

* Cluster errors by CFDA (Table A6)
eststo: reghdfe count_ht_mode_start_2012 post  if in_sample==1, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster modal_cfda) keepsingletons 


*Output 
esttab using "$results/regs_OLS_07122021.csv", label nogaps r2 ar2 star(* 0.1 ** 0.05 *** 0.01) b(%9.4g) se(%9.4g) scalars(widstat N_clust) sfmt(%9.0g) replace




*Table A.4 The Effects of Federal Funding Jumps on High-tech Enterprenerurship
u "$datadir/jobhist_lehd_E_20220614_pos_shock.dta", clear
eststo: reghdfe count_ht_mode_start_2012 post, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster emp_num) keepsingletons

sum count_ht_mode_start_2012

*Table A.4 The Effects of Federal Funding Cuts on High-tech Enterprenerurship at the Lab Level
u "$datadir/jobhist_lehd_E_20220614_all_neg_for_labs.dta"  , clear

gen people=1

collapse (sum) people count_ht_mode_start_2012, by(year pinumber_infill submit_u fieldid treated post)

drop if pinumber_infill==0
bys pinumber_infill: egen max_size = max(people)

eststo: reghdfe count_ht_mode_start_2012 post if max_size<100, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster pinumber_infill) keepsingletons

sum count_ht_mode_start_2012 if max_size<100, detail

*Output
esttab using "$results/results_2022_June.csv", label nogaps r2 ar2 star(* 0.1 ** 0.05 *** 0.01) b(%9.4g) se(%9.4g) scalars(widstat N_clust) sfmt(%9.0g) replace
 

 
*Unreported
u "$datadir/jobhist_lehd_E_06102021.dta", clear 
reghdfe count_ht_mode_start_2012 post, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster emp_num) keepsingletons 
gen in_sample=e(sample)
 
*By field , Univ*Yr*Field & PI FE
foreach field of varlist field_science field_engin field_bioMedPharma field_other {
sum `field'
eststo: reghdfe count_ht_mode_start_2012 post if `field'==1 & in_sample==1, a(i.year#i.submit_u#i.fieldid i.pinumber_infill) vce(cluster emp_num) keepsingletons 
}
